home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_6.arc / PEEPER.ASM < prev    next >
Assembly Source File  |  1989-07-31  |  3KB  |  142 lines

  1. ;****************************************************************
  2. ;*
  3. ;*    PEEPER.ASM -    Assembly subroutines to move memory from a 4G linear
  4. ;*            address into a buffer in the current data segment
  5. ;*
  6. ;*    Assembled using Microsoft Macro Assembler 5.1
  7. ;*
  8. ;****************************************************************
  9.  
  10. ;*    Need to use 80386 protected mode instructions
  11.     .386P
  12.  
  13.  
  14. KBC_IBF_BIT        EQU    02H
  15. KBC_WOP_CMD        EQU    0D1H
  16. KBC_ROP_CMD        EQU    0D0H
  17. A20_OFF_DATA        EQU    0DDH
  18. A20_ON_DATA        EQU    0DFH
  19. KBC_NOP_CMD        EQU    0FFH
  20.  
  21. KBC_DATA_PORT        EQU    060H
  22. KBC_CMD_PORT        EQU    064H
  23.  
  24. GA20_FAIL_ERR_CODE    EQU    0FFFFH
  25.  
  26. _TEXT    segment    use16 public    'CODE'
  27.     assume    cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  28.  
  29.  
  30. ;****************************************************************
  31. ;*    get_high_mem(dest,len,source) - copy memory from source to dest (len bytes)
  32. ;*    Entry    -    dest -        buffer in current DS
  33. ;*            len -        size of buffer in bytes
  34. ;*            source -    32-bit linear address of source memory
  35. ;*    Exit    -    gs: set to zero
  36. ;*    WARNING:    Forces GateA20 low when done
  37. ;****************************************************************
  38.         public    _get_high_mem
  39. ghm_dest    equ    word ptr [bp+4]
  40. ghm_len        equ    word ptr [bp+6]
  41. ghm_source    equ    dword ptr [bp+8]
  42. _get_high_mem    proc    near
  43.         push    bp
  44.         mov    bp, sp
  45.         push    di
  46.  
  47.         mov    al, 080h            ; allow normal A20
  48.         call    gate_A20
  49.  
  50.         xor    ax, ax
  51.         mov    gs, ax                ; zero out gs
  52.         mov    ax, ds
  53.         mov    es, ax                ; es := ds
  54.         mov    di, ghm_dest
  55.         mov    cx, ghm_len
  56.         mov    ebx, ghm_source
  57.         jcxz    ghm_bottom
  58. ghm_top:
  59.         mov    al, byte ptr gs:[ebx]
  60.         inc    ebx
  61.         stosb
  62.         loop    ghm_top
  63. ghm_bottom:
  64.         xor    al, al            ; cripple A20 for DOS
  65.         call    gate_A20
  66.  
  67.         pop    di
  68.         pop    bp
  69.         ret
  70.  
  71. _get_high_mem    endp
  72.  
  73. ;****************************************************************
  74. ;*    gate_A20(how)    -     set gateA20 to the desired state
  75. ;*    Entry    - AL==80h => A20 on
  76. ;*          AL==00h => A20 off
  77. ;*    Exit    -    GateA20 in desired state
  78. ;*    WARNING:    Assumes preferred states of output port bits
  79. ;****************************************************************
  80.  
  81. ;
  82. ;    gate_A20 -     set gateA20 to the desired state
  83. ;        Entry -    AL==80h => A20 on (no 1M wrap)
  84. ;            AL==00h => A20 off (1M wrap)
  85. ;
  86. gate_A20    proc    near
  87.         test    al,080H            ; al&80 = 0 ?
  88.         jnz    short ga20_on
  89. ;    al is zero, turn a20 off
  90.         mov    ah,A20_OFF_DATA        ; kbc off gate a20
  91.         call    empty_KBC        ; clear to use
  92.         jnz    short ga20_err        ; didn't clear
  93.         jmp    short ga20_KBC_ctl    ; cleared, go fix KBC A20
  94. ga20_on:
  95.         mov    ah,A20_ON_DATA        ; kbc on gate a20 if needed
  96. ga20_KBC_ctl:
  97.         mov    al,KBC_WOP_CMD        ; Write Output Port
  98.         out    KBC_CMD_PORT,al        ; command it
  99.         call    empty_KBC
  100.         jnz    short ga20_err
  101.         mov    al,ah
  102.         out    KBC_DATA_PORT,al
  103.         call    empty_KBC        ; wait till it clears
  104.         jnz    short ga20_err        ; didn't clear
  105.         mov    al,KBC_NOP_CMD        ; flush it through
  106.         out    KBC_CMD_PORT,al        ; command it
  107.         call    empty_KBC
  108.         jnz    short ga20_err
  109. ;    we're here, it worked!!
  110. ga20_ok:
  111.         xor    ax,ax
  112.         jmp    short ga20_out
  113. ga20_err:
  114.         mov    ax,GA20_FAIL_ERR_CODE
  115. ga20_out:
  116.         ret
  117. gate_A20    endp
  118.  
  119. ;
  120. ;    empty_KBC -    Empty keyboard controller input buffer
  121. ;        Entry -    none
  122. ;        Exit  -    bashes AL
  123. ;
  124. empty_KBC    proc    near
  125.         push    cx            ; save reg
  126.         xor    cx,cx            ; set for max timeout
  127. empty_KBC_loop:
  128.         in    al,KBC_CMD_PORT        ; get KBC status
  129.         test    al,KBC_IBF_BIT        ; check IBF bit
  130.         loopnz    empty_KBC_loop        ; try till timeout
  131.         pop    cx            ; restore reg
  132.         ret                ; that's all folks
  133. empty_KBC    endp
  134.  
  135.  
  136.  
  137.  
  138. _TEXT    ends
  139.     end
  140.  
  141.  
  142.